package com.library.admin.modules.menu.vo;

import java.time.LocalDateTime;

import com.library.admin.modules.menu.entity.Menu;
import lombok.Data;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 后台管理菜单表(Menu)VO类
 *
 * @author xyh
 * @since 2023-10-02 15:09:36
 */
@Data
public class MenuVO implements Serializable {
    @TableField(exist = false)
    private static final long serialVersionUID = -25385952045636722L;

    /**
     * 菜单主键ID
     */
    private Integer id;
    /**
     * 菜单名称
     */
    private String name;
    /**
     * 导航路径
     */
    private String path;
    /**
     * 组件路径
     */
    private String component;
    /**
     * 路径匹配规则
     */
    private String url;
    /**
     * 重定向地址
     */
    private String redirect;
    /**
     * 标题
     */
    private String title;
    /**
     * 菜单图标
     */
    private String icon;
    /**
     * 排序,越小越靠前
     */
    private Integer orderNo;
    /**
     * 父菜单ID
     */
    private Integer parentId;
    /**
     * 隐藏菜单，为0时是展示在左侧导航栏中的
     */
    private Integer hideMenu;
    /**
     * 当前路由不再标签页显示
     */
    private Integer hideTab;
    /**
     * 隐藏该路由在面包屑上面的显示
     */
    private Integer hideBreadcrumb;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
    /**
     * 修改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;
    /**
     * 备注
     */
    private String remark;

    private List<MenuVO> children;

    private Meta meta;

    public MenuVO(Menu menu){
        this.id = menu.getId();
        this.path = menu.getPath();
        this.name =menu.getName();
        this.url = menu.getUrl();
        this.component = menu.getComponent();
        this.redirect = menu.getRedirect();
        this.orderNo = menu.getOrderNo();
        this.parentId = menu.getParentId();
        this.title = menu.getTitle();
        this.icon = menu.getIcon();
        this.remark = menu.getRemark();
        this.createTime = menu.getCreateTime();
        this.hideMenu = menu.getHideMenu();
        this.children = new ArrayList<>();
        this.meta = new Meta(menu);
    }

    @Data
    static class Meta {
        private String title;
        private String icon;
        private Integer hideTab;
        private Integer hideBreadcrumb;
        private Integer hideMenu;

        public Meta(){}
        public Meta(Menu menu) {
            this.title= menu.getTitle();
            this.icon = menu.getIcon();
            this.hideTab =menu.getHideTab();
            this.hideBreadcrumb =menu.getHideBreadcrumb();
            this.hideMenu =menu.getHideMenu();
        }
    }
}
